package extenstion

import java.util.*

/**
 * 伴生对象的扩展
 */
class ExtCom {

    companion object {
        fun calculate(a: Int, b: Int): Int = a + b
    }

}

//扩展半生对象方法
fun ExtCom.Companion.const(fa: String, fb: String): String = fa + fb;

//实用扩展
fun Int.Companion.random() = Random().nextInt()

fun Int.Companion.random(range: Int) = Random().nextInt(range)

fun main(args: Array<String>) {
    println(ExtCom.calculate(3, 2))
    println(ExtCom.const("Hello", " World!"))

    println("整形随机数：${Int.random()}")
    println("整形随机数：${Int.random(100)}")
}


